<%--
  Created by IntelliJ IDEA.
  User: YTY
  Date: 2016/3/30
  Time: 20:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>解码报告</title>
    <!-- Bootstrap -->
    <link href="/jsp/common/css/bootstrap.min.css" rel="stylesheet">
    <link href="/jsp/common/css/font-awesome.min.css" rel="stylesheet">
    <link href="/jsp/common/css/bootstrap-extend.css" rel="stylesheet">
    <script src="/jsp/common/js/jquery.min.js"></script>
    <script src="/jsp/common/js/bootstrap.min.js"></script>
    <script src="/jsp/common/js/angular.min.js"></script>
    <link href="/jsp/common/css/viewer.min.css" rel="stylesheet">
    <script src="/jsp/common/js/viewer.min.js"></script>
    <script src="/jsp/common/js/module/entityModule.js"></script>
    <script src="/jsp/common/js/module/listModule.js"></script>
    <script src="/jsp/common/js/module/pageModule.js"></script>
    <script>
        var m = angular.module("m", ["nm", 'entityModule','listModule']);
        var c = m.controller("c", function ($scope, ajax, $filter, $rootScope,$timeout) {
            $scope.editEnable = false;
            $scope.editTotalEnable = false;
            $scope.cancelEdit = false;
            $scope.cancelTotalEdit = false;

            $scope.list = [];
            $scope.detection = {};
            $scope.photos = [];
            $scope.isVerify = <%=request.getParameter("verify")%>;
            if ($scope.isVerify) {
                $rootScope.index = "系统设置管理";
                $rootScope.subIndex = "解码结果审核";
            } else {
                $rootScope.index = "顾客管理";
            }

            $scope.$watch('$viewContentLoaded', function () {
                $scope.ajaxsInit = function () {
                    ajax.ajax("/server/redirect/detection/detection/getDetectionResultsByDetectionAdmin", "POST", {
                        userId: userId,
                        customerId:<%=request.getParameter("customerId")%>,
                        detectionId: <%=request.getParameter("detectionId")%>
                    }).success(function (data) {
                        if (data.success) {
                            console.log(data);
                            $scope.detection = data.value;
                            $scope.listAll = data.list;
                            $scope.list = data.list.slice(0,24);//去掉综合分析
                            $scope.photos = data.photos;
                            /**
                             * 调整顺序
                             * 0 1 2 3 4 5 6 7 *** 8 9 10 11 12 13 14 15 *** 16 17 18 19 20 21 22 23
                             * 0 8 16 1 9 17 2 10 18 3 11 19 4 12 20 5 13 21 6 14 22 7 15 23
                             * @type {Array}
                             */
                            var listTemp = new Array();
                            for(var i=0;i<24;i++){
                                listTemp[0]=$scope.list[0]; listTemp[1]=$scope.list[8]; listTemp[2]=$scope.list[16];
                                listTemp[3]=$scope.list[1]; listTemp[4]=$scope.list[9]; listTemp[5]=$scope.list[17];
                                listTemp[6]=$scope.list[2]; listTemp[7]=$scope.list[10]; listTemp[8]=$scope.list[18];
                                listTemp[9]=$scope.list[3]; listTemp[10]=$scope.list[11]; listTemp[11]=$scope.list[19];
                                listTemp[12]=$scope.list[4]; listTemp[13]=$scope.list[12]; listTemp[14]=$scope.list[20];
                                listTemp[15]=$scope.list[5]; listTemp[16]=$scope.list[13]; listTemp[17]=$scope.list[21];
                                listTemp[18]=$scope.list[6]; listTemp[19]=$scope.list[14]; listTemp[20]=$scope.list[22];
                                listTemp[21]=$scope.list[7]; listTemp[22]=$scope.list[15]; listTemp[23]=$scope.list[23];
                            }
                            /**
                             * 插入评价
                             * 24 21 18 15 12 9 6 3
                             * @type {Array}
                             */
                            var listTempTwo = listTemp;
                            for(var i1=8;i1>0;i1--){
                                var j = i1*3;
                                var obj = {};
                                obj.detectionIndex = listTempTwo[j-1].detectionIndex;
                                obj.commentName = listTempTwo[j-1].detectionIndex.name;

                                if(j == 24){
                                    obj.index = 23+i1;
                                    listTemp.push(obj);
                                    continue ;
                                }
                                obj.index = 23+i1;
                                listTemp.splice(j,0,obj);//替换某个元素
                            }
                            $scope.list = listTemp;
                            //console.log($scope.list);
                            //获取单个专家
                            ajax.ajax("/server/expert/getExpertAdmin", "POST", {
                                userId: userId,
                                expertId:$scope.detection.expertId
                            }).success(function (data) {
                                console.log(data);
                                /**
                                 * entity.refereeId = referee.id;
                                 entity.refereeName = referee.name;
                                 entity.refereePortrait = referee.portrait;
                                 */
                                $scope.referee.entity.refereeId = data.value.id;
                                $scope.referee.entity.refereeName = data.value.name;
                                $scope.referee.entity.refereePortrait = data.value.portrait;
                            });
                        } else {
                            alert(data.message);
                        }
                    });
                };
                $scope.ajaxsInit();

                /**
                 * 切换编辑状态
                 * @param row
                 * @returns {string}
                 */
                $scope.changeEditStatus = function () {//单项指标
                    $scope.editEnable = !$scope.editEnable;
                    if(!$scope.editEnable){
                        $scope.cancelEdit = true;
                        $timeout(function () {
                            $scope.cancelEdit = false;
                        },1500);
                        $scope.ajaxsInit();
                    }
                };
                $scope.changeEditTotalStatus = function () {//综合评价
                    $scope.editTotalEnable = !$scope.editTotalEnable;
                    if(!$scope.editTotalEnable){
                        $scope.cancelTotalEdit = true;
                        $timeout(function () {
                            $scope.cancelTotalEdit = false;
                        },1500);
                        $scope.ajaxsInit();
                    }
                };
                /**
                 * 编辑单项指标评价
                 * @param row
                 * @returns {string}
                 */
                $scope.editSingleComment = function () {
                    $scope.indexIds = [];
                    $scope.evaluations = [];
                    for(var t1=24;t1<32;t1++){
                        this.indexIds[t1-24] = $scope.listAll[t1].detectionIndex.id;
                        this.evaluations[t1-24] = $scope.listAll[t1].result;
                    }

                    /**
                     * int detectionId, int expertId,String expertName,int indexIds,String evaluations
                     */
                    ajax.ajax("/server/redirect/detection/detection/expertEvaluateIndex", "POST", {
                        detectionId: <%=request.getParameter("detectionId")%>,
                        expertId:$scope.referee.entity.refereeId,
                        expertName:$scope.referee.entity.refereeName,
                        indexIds:$scope.indexIds,
                        evaluations:$scope.evaluations
                    }).success(function (data) {
                        console.info(data);
                        $scope.changeEditStatus();
                        //改变综合评价
                        $scope.editTotalCommentTemp = "";
                        for(var i=0;i<8;i++){
                            $scope.editTotalCommentTemp += ((i+1)+"."+$scope.evaluations[i]+"\n");
                        }
                        $scope.detection.result = $scope.editTotalCommentTemp;
                        $scope.changeEditTotalStatus();
                        $scope.editTotalComment();
                    });
                };
                /**
                 * 编辑综合评价
                 */
                $scope.editTotalComment = function () {
                    /**
                     * int detectionId, int expertId,String expertName,String result
                     */
                    ajax.ajax("/server/redirect/detection/detection/expertEvaluateResult", "POST", {
                        detectionId: <%=request.getParameter("detectionId")%>,
                        expertId:$scope.referee.entity.refereeId,
                        expertName:$scope.referee.entity.refereeName,
                        result:$scope.detection.result
                    }).success(function (data) {
                        console.info(data);
                        $scope.changeEditTotalStatus();
                    });
                };
            });

            $scope.score = function (row) {
                if (row.detectionIndex.unit == "%") {
                    return (row.score * 100).toFixed(3) + row.detectionIndex.unit;
                } else {
                    return row.score.toFixed(3) + row.detectionIndex.unit;
                }
            };
            $scope.reference = function (row) {
                var rowCom;
                for(var i = 24;i< $scope.listAll.length;i++){
                    if($scope.listAll[i].detectionIndex.id == row.detectionIndex.id){
                        rowCom = $scope.listAll[i];
                        break;
                    }
                }
                if (rowCom.detectionIndex.unit == "%") {
                    return (rowCom.referenceFloor*100).toFixed(3) + "~" + (rowCom.referenceCeil*100).toFixed(3) + rowCom.detectionIndex.unit;
                } else {
                    return rowCom.referenceFloor.toFixed(3) + "~" + rowCom.referenceCeil.toFixed(3) + rowCom.detectionIndex.unit;
                }
            };
            $scope.verify = function (verify) {
                ajax.ajax("/server/redirect/detection/detection/updateDetectionAdminVerify", "POST",
                        {
                            userId: userId,
                            id: $scope.detection.id,
                            verify: verify
                        }).success(function (data) {
                            if (data.success) {
                                alert("审核成功");
                                window.close();
                            } else {
                                alert(data.message);
                            }
                        });
            };
            //点击解码图放大(全屏)显示
            $scope.viewPicFullScreen = function (path) {
                $scope.fullScreenPicPath = path;
                $(".popup").css("display","block");
            };
            $scope.viewPicFullScreenReturn = function () {
                $(".popup").css("display","none");
            };
            $scope.referee = {
                entity:{refereeId:0},
                page: {},
                service: function (page) {
                    this.page = page;
                },
                load: function (current, size, name, callback) {
                    ajax.ajax("/server/expert/getExpertsAdmin", "POST",
                            {
                                userId: userId,
                                status: -1,
                                search: name,
                                current: current,
                                size: size
                            }).success(function (data) {
                        if (data.success) {
                            console.log(data);
                            callback(data);
                        }
                    });
                },
                plus: function (referee) {
                    var entity = $scope.referee.entity;
                    entity.refereeId = referee.id;
                    entity.refereeName = referee.name;
                    entity.refereePortrait = referee.portrait.path;
                }
            };
        });
    </script>
    <style type="text/css">
        .popup{
            position: fixed;
            left: 0px;
            top: 0px;
            width: 100%;
            height: 100%;
            text-align: center;
            display: none;
            z-index: 2501;
        }
        .popup .popup-bg{
            background-color: rgba(0,0,0,0.5);
            width: 100%;
            height: 100%;
        }
        /*@media \0screen\,screen\9 {
            #popup .bg{
                background-color:#000000;
                filter:Alpha(opacity=50);
                position:static;
            }
            #popup .bg img{
                position: relative;
            }
        }*/
        .popup img{
            max-width: 100%;
            max-height: 100%;
        }
        textarea{/*文本域不能拖拽*/
            outline:none;
            resize:none;
        }
    </style>
</head>
<body ng-app="m">
<jsp:include page="nav.jsp"/>
<div class="container-fluid m-a-lg" ng-controller="c" style="max-width: 800px">

    <div class="row p-a p-t-lg" style="background-color: #d6cbd6">
        <div class="col-xs-2 p-r-0">
            <a ng-href='{{"/jsp/customer/customer/customer.jsp?customerId=" + detection.customerId}}' target="_blank">
                <img class="img-responsive img-circle" ng-src="{{detection.customerPortraitThumb}}">
            </a>

            <div class="ng-hide m-t-md" ng-show="isVerify && detection.adminVerify == null">
                <button class="btn btn-success btn-xs center-block" ng-click="verify(true)">通过审核</button>
                <button class="btn btn-danger btn-xs center-block m-t" ng-click="verify(false)">拒绝审核</button>
            </div>
        </div>
        <div class="col-xs-10 text-white">
            <div class="row">
                <p class="col-xs-2">姓名</p>

                <p class="col-xs-3" ng-bind="detection.customerName"></p>

                <p class="col-xs-2">美容机构</p>

                <p class="col-xs-5" ng-bind="detection.parlorName"></p>
            </div>
            <div class="row">

                <p class="col-xs-2">性别</p>

                <p class="col-xs-3" ng-bind="detection.gender"></p>

                <p class="col-xs-2">终端</p>

                <p class="col-xs-5" ng-bind="detection.equipmentType"></p>
            </div>
            <div class="row">

                <p class="col-xs-2">年龄</p>

                <p class="col-xs-3" ng-bind="detection.age"></p>

                <p class="col-xs-2">所在地</p>

                <p class="col-xs-5" ng-bind="detection.area.mergerName | mergerArea"></p>
            </div>
            <div class="row">
                <p class="col-xs-2">民族</p>

                <p class="col-xs-3" ng-bind="detection.nation"></p>

                <p class="col-xs-2">解码时间</p>

                <p class="col-xs-5" ng-bind="detection.createTime | fmtDatetime"></p>
            </div>
            <div class="row">
                <p class="col-xs-2">综合评分</p>

                <p class="col-xs-3" ng-bind="detection.score"></p>

                <p class="col-xs-2">排名</p>

                <p class="col-xs-5" ng-bind="detection.rank"></p>
            </div>

        </div>
    </div>
    <br>
    <%--选择专家--%>
    <div class="form-group">
        <label class="col-sm-2 control-label" style="background-color: #f5d1e4;margin-left: -15px;">
            <span class="text-danger small icon-asterisk m-r"></span><span class="text-danger">专家</span>
        </label>
        <script type="text/ng-template" id="referee_template.html">
            <div class="clearfix">
                <img class="pull-left img-responsive img-rounded" style="width: 32px;height: 32px"
                     ng-src="{{row.portrait.path}}">

                <p class="m-y" ng-bind="row.name" style="margin-left: 4em">
                </p>
            </div>
        </script>

        <div class="col-sm-10">
            <div class="col-xs-6">
                <h4 class="text-center text-success">评价专家</h4>

                <div ng-if="referee.entity.refereeId>0"
                     class="row list-group-item list-group-item-success">
                    <img class="img-responsive img-rounded pull-left" style="width: 32px;height: 32px"
                         ng-src="{{referee.entity.refereePortrait}}">

                    <p class="m-y" ng-bind="referee.entity.refereeName" style="margin-left: 4em"></p>
                </div>

            </div>
            <div class="col-xs-6">
                <div class="row" list-page service="referee.service($page)" template-id="referee_template.html"
                     select="referee.plus($row)"
                     height="500px" placeholder="专家姓名"
                     load="referee.load($current, $size, $name, $callback)">
                </div>
            </div>

        </div>

    </div>

    <div class="clearfix"></div>
    <h4 class="row">皮肤指标解码值：</h4>

    <div class="row">
        <p class="col-xs-2 p-y-md m-y-0" style="background-color: #f5e1f5">指标</p>

        <p class="col-xs-2 p-y-md m-y-0" style="background-color: #d06bf2">类型</p>

        <p class="col-xs-2 p-y-md m-y-0" style="background-color: #c29dc2">解码值</p>

        <p class="col-xs-2 p-y-md m-y-0" style="background-color: #5c93e5">等级</p>

        <p class="col-xs-2 p-y-md m-y-0" style="background-color: #95b5e6">参考值</p>

        <p class="col-xs-2 p-y-md m-y-0" style="background-color: #f5d1e4">样图</p>
    </div>
    <div class="row" ng-repeat="row in list" ng-style='{"background-color":$index%2==0?"#c5ccd6":"#e8e9eb"}'>
        <div ng-if="row.commentName">
        <p class="col-xs-2 p-y-md m-y-0">
            <span ng-bind="row.detectionIndex.name" style="color:#c7254e;"></span>&nbsp;
            <span style="font-weight: bold;font-style: italic;color: #c7254e">评价</span>
        </p>
        <p class="col-xs-10 p-y-md m-y-0">
            <%--<button ng-click="viewCommentModal(row)" class="btn btn-info btn-xs">查看当前评价</button>
            <button ng-click="editSingleCommentModal(row)" class="btn btn-success btn-xs form-inline">编辑评价</button>--%>
            <textarea ng-disabled="!editEnable" rows="6" class="form-control" ng-model="listAll[row.index].result"></textarea>
        </p>
        </div>

        <div ng-if="!row.commentName">
        <p class="col-xs-2 p-y-md m-y-0"
           style="border-right: #bbbbbb 1px solid"><%--<span ng-bind="row.face"></span>--%>
            <span ng-bind="row.detectionIndex.name"></span></p>

        <p class="col-xs-2 p-y-md m-y-0" ng-bind="row.face" style="border-right: #bbbbbb 1px solid;"></p>

        <p class="col-xs-2 p-y-md m-y-0" ng-bind="score(row)" style="border-right: #bbbbbb 1px solid"></p>

        <p class="col-xs-2 p-y-md m-y-0" ng-bind="row.level" style="border-right: #bbbbbb 1px solid"></p>

        <p class="col-xs-2 p-y-md m-y-0" ng-bind='reference(row)' style="border-right: #bbbbbb 1px solid"></p>

        <p class="col-xs-2 p-y-md m-y-0">
            <img width="30px" height="20px" class="img-rounded" ng-src="{{row.photoThumb.path}}"
                 style="cursor: pointer;" ng-click="viewPicFullScreen(row.photo.path)" data-url="{{row.photo.path}}">
        </p>
        </div>
    </div>

    <br>
    <div style="padding: 0">
        <button ng-click="changeEditStatus()" class="btn btn-info" style="margin-left: -15px;" ng-show="!editEnable">
            <span class="glyphicon glyphicon-edit"></span>
            &nbsp;编辑</button>
        <button ng-click="changeEditStatus()" class="btn btn-danger" style="margin-left: -15px;" ng-show="editEnable">
            <span class="glyphicon glyphicon-remove"></span>
            &nbsp;取消编辑</button>
        <button ng-click="editSingleComment()" class="btn btn-success" ng-show="editEnable">
            <span class="glyphicon glyphicon-ok"></span>
            &nbsp;提交</button>&nbsp;
        <span ng-show="cancelEdit" class="text-muted"><i class="icon-spin icon-spinner icon-large"></i>&nbsp;操作中,请稍后 ......</span>
    </div>

    <div ng-click="viewPicFullScreenReturn()" class="popup">
        <div class="popup-bg"><img ng-src="{{fullScreenPicPath}}" alt=""/></div>
    </div>

    <%--<h4 class="row">皮肤指标采样图：</h4>

    <div class="row" entity-modal-img="data-url">
        <div class="pull-left p-x" ng-repeat="row in list" ng-style='{"width":100/list.length+"%"}'>
            <img class="img-responsive img-rounded" ng-src="{{row.photoThumb.path}}"
                 style="width: 100%" data-url="{{row.photo.path}}">

            <p class="text-center" ng-bind="row.detectionIndex.name"></p>
        </div>
    </div>

    <div class="row p-t">
        <div class="pull-left" ng-repeat="row in photos" ng-style='{"width":100/photos.length+"%"}'>
            <p class="text-center" ng-bind="row.detectionPhotoIndex.name"></p>
        </div>
    </div>--%>
    <br>

    <div class="row p-a-md" style="background-color: #f5e1f5;margin-bottom: 10px;">
        <p>综合分析：&nbsp;
            <button ng-click="changeEditTotalStatus()" class="btn btn-info" style="" ng-show="!editTotalEnable">
                <span class="glyphicon glyphicon-edit"></span>
                &nbsp;编辑</button>
            <button ng-click="changeEditTotalStatus()" class="btn btn-danger" ng-show="editTotalEnable">
                <span class="glyphicon glyphicon-remove"></span>
                &nbsp;取消编辑</button>
            <button ng-click="editTotalComment()" class="btn btn-success" ng-show="editTotalEnable">
                <span class="glyphicon glyphicon-ok"></span>
                &nbsp;提交
            </button>
            <span ng-show="cancelTotalEdit" class="text-muted"><i class="icon-spin icon-spinner icon-large"></i>&nbsp;操作中,请稍后 ......</span>
        </p>

        <textarea ng-disabled="!editTotalEnable" rows="30" class="form-control"
                  style="/*text-indent: 2em*/" ng-model="detection.result"></textarea>
    </div>

</div>

<script type="text/javascript">

</script>
</body>
</html>
